<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MVCWeb.Models.Doc>" %>

<%@ Import Namespace="MVCWeb.Helpers" %>
<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Edit a document</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function deleteRecord(recordId) {
            if (confirm("Are you sure to delete this doc?")) {
                // Perform delete
                var action = '<%= Url.Action("Delete", "Doc") %>/' + recordId;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(deleteCompleted);
                request.invoke();
            }
        }

        function deleteCompleted() {
            // Goback
            window.back();
        }    
    </script>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#DocumentForm").validate({
                rules: {
                    Name: {
                        required: true
                    }
                },
                messages: {
                    Name: {
                        required: "Name cannot be blank"
                    }
                }
            });
            $("#submit_view").click(function() {
                $("#IsRedirectToView").val("true");
            });
            $("#delete").click(function() {
                $("#IsRedirectToView").val("true");
            });
        });
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
    <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <br />
    <br />
    <%= Html.ValidationSummary() %>
    <% using (Html.BeginForm("Edit", "Doc", FormMethod.Post, new { id = "DocumentForm", enctype = "multipart/form-data" }))
       {%>
    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="Name">
                Name:</label>
            <%= Html.TextBox("Name", ViewData.Model.Name, new { style = "width: 400px;"})%>
            <%= Html.ValidationMessage("Name", "*") %>
        </p>
        <p>
            <label for="Desc">
                Description:</label>
            <%= Html.TextBox("Desc", ViewData.Model.Desc, new { style = "width: 400px;" })%>
            <%= Html.ValidationMessage("Desc", "*") %>
        </p>
        <p>
            <label for="FullPath">
                Filename:</label>
            <input type="file" name="FullPath" id="FullPath" size="34" />
            <%= Html.ValidationMessage("FullPath", "*") %>
        </p>
        <p>
            <label for="ParentCategoryId">
                Category:</label>
            <%= Html.DropDownList("ParentCategoryId")%>
            <%= Html.ValidationMessage("ParentCategoryId", "*")%>
        </p>
        <p>
            <label for="DocCategoryId">
                Sub Category:</label>
            <%= Html.CascadingDropDownListJQuery("DocCategoryId", "ParentCategoryId",Model.DocCategoryId.ToString())%>
        </p>
        <%= Html.Hidden(ViewData["CommunityId"].ToString()) %>
        <%= Html.Hidden("IsRedirectToView")%>
        <%--<p>
            <label for="CommunityId">
                Community:</label>
            <%= Html.DropDownList("CommunityId")%>
            <%= Html.ValidationMessage("CommunityId", "*")%>
        </p>--%>
        <p>
            <input id="submit" name="submit" type="submit" value="Update" />
            <input id="submit_view" name="submit_view" type="submit" value="Update & View" />
            <% if (Roles.IsUserInRole("Administrators"))
               { %>
            <input id="delete" name="delete" type="submit" value="Delete" onclick="deleteRecord(<%=Model.DocId%>); return false;" />
            <% } %>
            <input type="reset" value="Reset" />
        </p>
    </fieldset>
    <% } %>
    <div>
        <%=Html.ActionLink("Go back", "Index", "Community") %>
    </div>
</asp:Content>
